package com.dao;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.annotation.Resource;

import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;

import com.vo.UserVO;

/**
 * @author daou-ljhjoin
 *
 */
@Repository("userDAO")
public class UserDAO {
	
	@Resource(name="sqlMapClientTemplate")
	public SqlMapClientTemplate sqlmap;

	public UserVO selectUserById(String id) throws SQLException {
		return (UserVO)sqlmap.queryForObject("user.selectUserById", id);
	}
	
	@SuppressWarnings("unchecked")
	public ArrayList<UserVO> selectUserList() throws SQLException{
		return (ArrayList<UserVO>)sqlmap.queryForList("user.selectUserList");
	}

	public void registerUser(UserVO userVo) throws SQLException{
		sqlmap.insert("user.registerUser", userVo);
	}

	public UserVO updateUser(UserVO userVo) throws SQLException {
		sqlmap.update("user.updateUser", userVo);
		return selectUserById(userVo.getId());
	}

	public void deleteUser(String id) throws SQLException{
		sqlmap.delete("user.deleteUser", id);
	}
	
}
